#include "serverapp.h"
#include "pluginmanager.h"

#include <QDir>
#include <QDebug>

#include "project.h"

#define PLUGIN_DIR "../plugins"

#ifndef PLUGIN_DIR
#error PLUGIN_DIR must be defined!
#endif

CServerApp::CServerApp()
{
	createPluginManager();
	testProject();
}

CServerApp::~CServerApp()
{
	delete m_pProject;
}


bool CServerApp::createPluginManager()
{
	// create plugin manager and scan for plugins. THe first bit is easy:
	CPluginManager *pm = CPluginManager::getPluginManager();

	// work out directories for plugins and python lib code:
	QDir pluginDir( PLUGIN_DIR );
	if (!pluginDir.exists())
	{
		qDebug() << PLUGIN_DIR <<  pluginDir.absolutePath();
		Q_ASSERT_X(0, Q_FUNC_INFO, "Plugin directory does not exist!");
		return false;
	}

	QDir pluginLibDir = pluginDir;
	pluginLibDir.cd("lib");
	if (!pluginDir.exists())
	{
		Q_ASSERT_X(0, Q_FUNC_INFO, "Plugin lib directory does not exist!");
		return false;
	}

	pm->setPluginDir(pluginDir.absolutePath());
	pm->setLibDir(pluginLibDir.absolutePath());

	pm->scanPlugins();

	return true;
}

void CServerApp::testProject()
{
	/*
	qDebug() << "Running Test Project...";

	const QString strSettingsPath("./Settings.xml");
	m_pProject = new CProject(strSettingsPath);

	m_pProject->runProject();
	*/
}
